/**
 * Copyright © 2022 易久批信息技术有限公司. All rights reserved.
 */
package com.dysm.hashmap;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author xiay
 * @since 2022/2/26 2:17 下午
 */
public class HashMapTest {

    public static void main(String[] args) {
//        int cap = 36;
//        int size = tableSizeFor(cap);
//        System.out.println("cap:" + cap + "-----size:" + size);
//        System.out.println(Integer.toBinaryString(cap));
//        System.out.println(Integer.toBinaryString(size));

//        int str = hash("straaa");
//        System.out.println(str);
        Map<Integer, String> map = new HashMap<>();
        int i = 1;
        map.put(i, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
        map.put(i = i + 16, "3423423");
//
//        long round = Math.round(1.5);
//        System.out.println("round(1.5):" + round);
//        round = Math.round(-1.5);
//        System.out.println("round(-1.5):" + round);
//        round = Math.round(1.1);
//        System.out.println("round(1.1):" + round);
//
//        byte b = 127;
//        byte bb = (byte) (b + 1);
//        System.out.println(bb);



    }


    private static int tableSizeFor(int cap) {
        int MAXIMUM_CAPACITY = 1 << 30;
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
    }

    private static int hash(String str) {
        int h;
        return (h = hashCode(str)) ^ (h >>> 16);
    }

    public static int hashCode(String str) {
        int hash = 0;
        char[] value = str.toCharArray();
        int h = hash;
        if (value.length > 0) {
            char val[] = value;

            for (int i = 0; i < value.length; i++) {
                h = 31 * h + val[i];
            }
            hash = h;
        }
        return h;
    }
}
